package com.example.menuvirtualclient.rule;

import java.util.Date;

import com.example.menuvirtualclient.core.*;
import com.example.menuvirtualclient.data.ISession;
import com.example.menuvirtualclient.data.SessionFactory;
import com.example.menuvirtualclient.repository.OrderRepository;

import android.content.Context;
import android.util.Log;

public class OrderRule {

	private ISession _session;
	private final OrderRepository _repository;
	
	/**
	 * 
	 * @param context
	 */
	public OrderRule(Context context){
		_session = SessionFactory.GetSession(context);
		_repository = new OrderRepository(context);
		Log.i("Info", "Paso por el context");
	}
	
	public Order GetEntity(String table) throws Exception {
		try {
			return new Order();
			//return _repository.GetAll();
			//return GetByTable(table);			
		} 
		catch (Exception ex) {
			throw ex;
		}
	}
	
	public Order Get(int id) throws Exception{
		try {
			_session.Open();
			return _repository.Get(id);			
		} 
		catch (Exception ex) {
			throw ex;
		}
		finally{
			_session.Close();
		}
	}
	
	public void Save(Order order) throws Exception{
		try {
			_session.Open();
			_repository.Insert(order);			
		} 
		catch (Exception ex) {
			throw ex;
		}
		finally{
			_session.Close();
		}
	}
	
	/*
	private Order GetByTable(String table) {
		Order order = new Order(
						1,
						12,
						new Date(),
						new Table(),
						new User());

		return order;
	}
	*/
}
